$(function() {
  $(':button#wossnquery').bind('click', function() {
    $.getJSON('/_wopassed', {
      wono: $("#wonos").val(),
      pageid: $("#spanPageNum").text(),
      station: $("#stats").val(),
      date: new Date().getTime()+Math.random()
    }, function(data) {
      var curr = data.wonos;
      var lang = data.lang;
      createTable(curr, lang);
    });
    return false;
  });
})

function createTable(tableList, flags)
{
  var s = '';
  s += "<table id='tbl_ls' border='1' cellspacing='0' cellpadding='0'>";
  s += "<thead>";
  s += "<tr>";
  if(flags == "zh_CN") {
    s += "<th>索引</th>";
    s += "<th>物料</th>";
    s += "<th>描述</th>";
    s += "<th>产品序号</th>";
    s += "<th>站点</th>";
    s += "<th>结果</th>";
    s += "<th>作业员</th>";
    s += "<th>日期</th>";  
  } else {
    s += "<th>Index</th>";
    s += "<th>Item</th>";
    s += "<th>Descrip</th>";
    s += "<th>Product No.</th>";
    s += "<th>Station</th>";
    s += "<th>Result</th>";
    s += "<th>Operator</th>";
    s += "<th>Datetime</th>";
  }  
  s += "</tr>";
  s += "</thead>";
  s += "<tbody id='group_one'>";
  for(var idx in tableList)
  {
    if(idx%2 == 0)
    {
      s += "<tr class='alt-row'>";
    }
    else
    {
      s += "<tr class=''>"; 
    }
    if(tableList[idx].Result == 'PASS' || tableList[idx].Result == 'NDF')
    {
      s += "<td id='detail_idx' fieldset style='color: #666666; border-style: groove; font-weight: bold; font-size: 14px'>"+tableList[idx].Index+"</td>";
      s += "<td id='detail_itm' fieldset style='color: #666666; border-style: groove; font-weight: bold; font-size: 14px'>"+tableList[idx].Item+"</td>";
      s += "<td id='detail_dsc' fieldset style='color: #666666; border-style: groove; font-weight: bold; font-size: 14px'>"+tableList[idx].Desc+"</td>";
      s += "<td id='detail_ssn' fieldset style='color: #666666; border-style: groove; font-weight: bold; font-size: 14px'><a href='/queryssn?q="+tableList[idx].Serial+"'>"+tableList[idx].Serial+"</a></td>";
      s += "<td id='detail_sta' fieldset style='color: #666666; border-style: groove; font-weight: bold; font-size: 14px'>"+tableList[idx].Curr+"</td>";      
      s += "<td id='detail_rst' fieldset style='background: #00CC00; border-style: groove; font-weight: bold; font-size: 14px'>"+tableList[idx].Result+"</td>";
      s += "<td id='detail_ope' fieldset style='color: #666666; border-style: groove; font-weight: bold; font-size: 14px'>"+tableList[idx].Oper+"</td>";
      s += "<td id='detail_dat' fieldset style='color: #666666; border-style: groove; font-weight: bold; font-size: 14px'>"+tableList[idx].Date+"</td>";
    }
    else
    {
      s += "<td id='detail_idx' fieldset style='background: #EFF000; border-style: groove; font-weight: bold; font-size: 14px'>"+tableList[idx].Index+"</td>";
      s += "<td id='detail_itm' fieldset style='background: #EFF000; border-style: groove; font-weight: bold; font-size: 14px'>"+tableList[idx].Item+"</td>";
      s += "<td id='detail_dsc' fieldset style='background: #EFF000; border-style: groove; font-weight: bold; font-size: 14px'>"+tableList[idx].Desc+"</td>";
      s += "<td id='detail_ssn' fieldset style='background: #EFF000; border-style: groove; font-weight: bold; font-size: 14px'><a href='/queryssn?q="+tableList[idx].Serial+"'>"+tableList[idx].Serial+"</a></td>";
      s += "<td id='detail_sta' fieldset style='background: #EFF000; border-style: groove; font-weight: bold; font-size: 14px'>"+tableList[idx].Curr+"</td>";
      s += "<td id='detail_rst' fieldset style='background: #E00000; color: #EFF000; border-style: groove; font-weight: bold; font-size: 14px'>"+tableList[idx].Result+"</td>";
      s += "<td id='detail_ope' fieldset style='background: #EFF000; border-style: groove; font-weight: bold; font-size: 14px'>"+tableList[idx].Oper+"</td>";
      s += "<td id='detail_dat' fieldset style='background: #EFF000; border-style: groove; font-weight: bold; font-size: 14px'>"+tableList[idx].Date+"</td>";
    }
    s += "</tr>";
  }
  s += "</tbody>";
  s += "</table>";
  obj1.innerHTML = s;
}

function pagequery()
{
  wossnquery.click();
}